#include <screenGame.hpp>

/*ctor*/ScreenGame::ScreenGame() {
	_clicked = 0;

	sf::Color *niceRed = new sf::Color(200, 60, 40, 255);

	myChar = sf::Shape::Rectangle(0, 0, 64, 64, *niceRed, 1, sf::Color::White);
	Attach(myChar, layers(0));

	myClick = sf::Shape::Circle(0, 0, 10.f, sf::Color::Blue, 1, sf::Color::White);
	Attach(myClick, layers(0));
	

}


void	ScreenGame::GetEvent(sf::Event &e) {
	if ( e.Type == sf::Event::Closed )
		_inputs[sf::Keyboard::Escape] = 1;
	if ( e.Type == sf::Event::KeyPressed ) {
		_inputs[e.Key.Code] = 1;
	}
	else if ( e.Type == sf::Event::KeyReleased )
		_inputs[e.Key.Code] = 0;

	if ( e.Type == sf::Event::MouseButtonPressed )
		_clicked = 1;
	else
		_clicked = 0;
}

int	ScreenGame::Update() {
	if ( _inputs[sf::Keyboard::Escape] ) return update_die;

	if ( _inputs[sf::Keyboard::Left] ) myChar.Move(-2.f, 0.f);
	else if ( _inputs[sf::Keyboard::Right] ) myChar.Move(2.f, 0.f);

	if ( _inputs[sf::Keyboard::Up] ) myChar.Move(0.f, -2.f);
	else if ( _inputs[sf::Keyboard::Down]  ) myChar.Move(0.f, 2.f);

	if ( _clicked ) {
		sf::Vector2i mouse = sf::Mouse::GetPosition();
		myClick.SetPosition(mouse.x, mouse.y);

	}

	return update_alive;
}
